using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
namespace Os.WebUI.Models
{
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
	public sealed class PropertiesMustMatchAttribute : ValidationAttribute
	{
		private const string _defaultErrorMessage = "'{0}' e '{1}' não conferem.";
		private readonly object _typeId = new object();
		public string ConfirmProperty
		{
			get;
			private set;
		}
		public string OriginalProperty
		{
			get;
			private set;
		}
		public override object TypeId
		{
			get
			{
				return this._typeId;
			}
		}
		public PropertiesMustMatchAttribute(string originalProperty, string confirmProperty) : base("'{0}' e '{1}' não conferem.")
		{
			this.OriginalProperty = originalProperty;
			this.ConfirmProperty = confirmProperty;
		}
		public override string FormatErrorMessage(string name)
		{
			return string.Format(CultureInfo.CurrentUICulture, ErrorMessageString, new object[]
			{
				this.OriginalProperty, 
				this.ConfirmProperty
			});
		}
		public override bool IsValid(object value)
		{
			PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
			object value2 = properties.Find(this.OriginalProperty, true).GetValue(value);
			object value3 = properties.Find(this.ConfirmProperty, true).GetValue(value);
			return object.Equals(value2, value3);
		}
	}
}
